package structure.Flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by LYJ on 2016/10/19.
 * 享元工厂角色
 */
public class FlyWeightFactory {
    private Map<String,ConcreteFlyweight> flyweightMap=new HashMap<>();
    public ConcreteFlyweight factory(String str){
        ConcreteFlyweight flyweight=flyweightMap.get(str);
        if(null==flyweight){
            flyweight=new ConcreteFlyweight(str);
            flyweightMap.put(str,flyweight);
        }
        return flyweight;
    }

    public int getFlyweightSize(){
        return flyweightMap.size();
    }

}
